package com.globallogic.dailyplanner.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.globallogic.dailyplanner.dto.RoleEnum;
import com.globallogic.dailyplanner.dto.User;

public interface UserRepository extends JpaRepository<User, Integer>{
	
//	TODO find way to make update query work correctly
//	@Query("UPDATE User SET active = true WHERE user.id = :id")
//	void activateUserById(@Param("id") int userId);
	
	@Query("SELECT user FROM User user where user.username = :username")
	public User findOneByUsername(@Param("username") String username);
	
	@Query("SELECT user FROM User user where user.email = :email")
	public User findOneByEmail(@Param("email") String email);
	
	@Query("SELECT COUNT(user) FROM User user where user.active = :status and user.role = :role")
	public long getUserCountByStatus(@Param("status") boolean status, @Param("role") RoleEnum role);
}
